package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.itheima.domain.db.UserSoulType;
import com.itheima.mapper.UserSoulTypeMapper;
import com.itheima.service.db.UserSoulTypeService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class UserSoulTypeServiceImpl implements UserSoulTypeService {

    @Autowired
    UserSoulTypeMapper userSoulTypeMapper;

    @Override
    public UserSoulType findByUserId(Long userId) {
        LambdaQueryWrapper<UserSoulType> qw = new LambdaQueryWrapper<>();
        qw.eq(UserSoulType::getUserId,userId);
        UserSoulType userSoulType = userSoulTypeMapper.selectOne(qw);
        return  userSoulType;
    }

    //保存用户报告信息
    @Override
    public void save(UserSoulType userSoulType) {
        userSoulTypeMapper.insert(userSoulType);
    }

    //更新用户报告信息
    @Override
    public void update(UserSoulType userSoulType) {
        LambdaUpdateWrapper<UserSoulType> uw = new LambdaUpdateWrapper<>();
        uw.eq(UserSoulType::getUserId,userSoulType.getUserId());
        userSoulTypeMapper.update(userSoulType,uw);
    }

    //查询相似
    @Override
    public List<UserSoulType> findByReportId(Integer reportId) {
        LambdaQueryWrapper<UserSoulType> qw = new LambdaQueryWrapper<>();
        qw.eq(reportId!=null,UserSoulType::getReportId,reportId);
        return userSoulTypeMapper.selectList(qw);
    }
}
